package com.ruoyi.oc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oc.domain.SalesOrderDetail;
import com.ruoyi.oc.service.ISalesOrderDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单明细Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/oc/detail")
public class SalesOrderDetailController extends BaseController
{
    private String prefix = "oc/detail";

    @Autowired
    private ISalesOrderDetailService salesOrderDetailService;

    @RequiresPermissions("oc:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询销售订单明细列表
     */
    @RequiresPermissions("oc:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SalesOrderDetail salesOrderDetail)
    {
        startPage();
        List<SalesOrderDetail> list = salesOrderDetailService.selectSalesOrderDetailList(salesOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售订单明细列表
     */
    @RequiresPermissions("oc:detail:export")
    @Log(title = "销售订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SalesOrderDetail salesOrderDetail)
    {
        List<SalesOrderDetail> list = salesOrderDetailService.selectSalesOrderDetailList(salesOrderDetail);
        ExcelUtil<SalesOrderDetail> util = new ExcelUtil<SalesOrderDetail>(SalesOrderDetail.class);
        return util.exportExcel(list, "销售订单明细数据");
    }

    /**
     * 新增销售订单明细
     */
    @RequiresPermissions("oc:detail:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售订单明细
     */
    @RequiresPermissions("oc:detail:add")
    @Log(title = "销售订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SalesOrderDetail salesOrderDetail)
    {
        return toAjax(salesOrderDetailService.insertSalesOrderDetail(salesOrderDetail));
    }

    /**
     * 修改销售订单明细
     */
    @RequiresPermissions("oc:detail:edit")
    @GetMapping("/edit/{detailId}")
    public String edit(@PathVariable("detailId") String detailId, ModelMap mmap)
    {
        SalesOrderDetail salesOrderDetail = salesOrderDetailService.selectSalesOrderDetailByDetailId(detailId);
        mmap.put("salesOrderDetail", salesOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售订单明细
     */
    @RequiresPermissions("oc:detail:edit")
    @Log(title = "销售订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SalesOrderDetail salesOrderDetail)
    {
        return toAjax(salesOrderDetailService.updateSalesOrderDetail(salesOrderDetail));
    }

    /**
     * 删除销售订单明细
     */
    @RequiresPermissions("oc:detail:remove")
    @Log(title = "销售订单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(salesOrderDetailService.deleteSalesOrderDetailByDetailIds(ids));
    }
}
